/**
 * 定义模块
 */
$(function() {
	app = new Vue({
		el : '#app',
		/**
		 * 定义数据
		 */
		data : {
			model : {}
		},
		/**
		 * 定义方法
		 */
		methods : {
			/**
			 * 查询
			 */
			getIdFromUrl:function(){
				var addr = location.href;
				var index = addr.lastIndexOf('/') + 1;
				var id = addr.substr(index);
				return id;
			},
			 closeWin: function() {
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);
			},

			finduser:function () {
				var id = this.getIdFromUrl();
				$.ajax({
				    type: "GET",
				    url: '/manager/card/get/'+id,
				    beforeSend: function () {
				    },
				    complete: function () {
				    },
				    error: function(request) {
				        alert("Connection error");
				    },
				    success: function(result) {
				        if (result.status == 0) {
				        	var data = result.data;
				        	app.model = data;
				        }
				    }
				});
				
			},
			updatestatus : function(id,status) {
				_self = this;
				layer.confirm('确认要操作吗？', function() {
					var tipIndex = null;
					var data = {  
							id:id,
							statue:status,
							operator:$("#operator").val()
						}  
					$.ajax({
						type : "POST",
						url : '/manager/card/updatestatus',
						data : JSON.stringify(data), //转JSON字符串  
					    dataType: 'json',  
					    contentType:'application/json;charset=UTF-8', //contentType很重要     
						beforeSend : function() {
							tipIndex = layer.load(0, {
								shade : false
							});
						},
						complete : function() {
							layer.close(tipIndex);
						},
						error : function(request) {
							layer.alert("系统出错");
						},
						success : function(data) {
							if (data.status == 0) {
								refreshParentList();
								layer.alert(data.message, function() {
									var index = parent.layer.getFrameIndex(window.name);
									parent.layer.close(index);
								});
							}else{
								layer.alert(data.message);
							}
						}
					});
				});
			},
			checksimilarpercent:function (id) {
				_self = this;
				var tipIndex = null;
				var data = {  
						id:id
					}  
					$.ajax({
						type : "POST",
						url : '/manager/card/checkSimilarPercent',
						data : JSON.stringify(data), //转JSON字符串  
					    dataType: 'json',  
					    contentType:'application/json;charset=UTF-8', //contentType很重要     
						beforeSend : function() {
							tipIndex = layer.load(1, {shade: [0.8, '#393D49']});	
						},
						complete : function() {
							layer.close(tipIndex);
						},
						error : function(request) {
							layer.alert("系统出错");
						},
						success : function(data) {
							if (data.status == 0) {
								layer.alert("检测成功");
								$("#similarPercent").val(data.message);
							}else{
								layer.alert(data.message);
							}
						}
					});
			},
	
			// 初始化
			init : function() {
				this.finduser();
			}
		}
	});

	app.init();
});